package com.justme.shipdfer.bean.base;

import com.justme.shipdfer.enums.RespCodeEnum;
import lombok.Data;

/**
 * @author shiv
 * @create 2021/4/11 4:51 下午
 */
@Data
public class R<T> {

    private Integer code;

    private String message;

    private T data;

    public R(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public R(RespCodeEnum respCodeEnum, T data) {
        this.code = respCodeEnum.getCode();
        this.message = respCodeEnum.getMessage();
        this.data = data;
    }

    public static <T> R<T> success(T data) {
        return new R<>(RespCodeEnum.SUCCESS, data);
    }

    public static R<String> fail(RespCodeEnum respCodeEnum) {
        return new R<>(respCodeEnum, null);
    }
}
